<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="16">
        <el-button @click="resetNameFilter">清除设备ID过滤器</el-button>
        <el-button @click="clearFilter">清除所有过滤器</el-button>
        <!-- <div style="display:inline">
          <el-input
            placeholder="请输入内容"
            prefix-icon="el-icon-search"
            v-model="svalue"
            size="medium"
            
          >
          </el-input>
        </div> -->
      </el-col>
    </el-row>
    <el-table
      ref="filterTable"
      :data="tableData"
      style="width: 100%"
      @row-click="handleRowClick"
    >
      <el-table-column type="index" label="维保编号" width="100">
      </el-table-column>
      <!-- <el-table-column prop="code" label="维保编号"> </el-table-column> -->
      <el-table-column prop="position" label="维保点"> </el-table-column>
      <el-table-column
        prop="id"
        label="设备ID"
        sortable
        column-key="name"
        :filters="getFilters('id')"
        :filter-method="filterHandler"
      >
      </el-table-column>
      <el-table-column prop="period" label="维保周期"> </el-table-column>
      <el-table-column prop="type" label="维保时间类型"> </el-table-column>
      <el-table-column prop="last" label="上次维保时间"> </el-table-column>
      <el-table-column label="维保周期倒计时">
        <template slot-scope="scope">
          <el-progress
            :percentage="scope.row.countdown"
            :color="colors"
            :show-text="false"
          ></el-progress>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="limit"
        layout="sizes, prev, pager, next"
        :total="tableData.length"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
// import table from "../../components/clients/table";
export default {
  components: {
    // table,
  },
  computed: {
    getTableData() {
      return;
    },
  },
  data() {
    return {
      currentPage: 1,
      limit: 10,
      svalue: "",
      dialogFormVisible: false,
      tableData: [
        {
          position: "控制系统-控制点检测",
          id: "1028",
          period: "1小时",
          type: "自然时间",
          last: "2019-09-24 16:01:20",
          countdown: 90,
        },
        {
          position: "控制系统-控制点检测",
          id: "1029",
          period: "1小时",
          type: "自然时间",
          last: "2019-09-24 16:09:30",
          countdown: 80,
        },
        {
          position: "控制系统-控制点检测",
          id: "1030",
          period: "1小时",
          type: "自然时间",
          last: "2019-09-24 16:07:20",
          countdown: 90,
        },
        {
          position: "控制系统-控制点检测",
          id: "1031",
          period: "1小时",
          type: "自然时间",
          last: "2019-09-24 16:09:20",
          countdown: 2,
        },
      ],
      colors: [
        { color: "#f56c6c", percentage: 20 },
        { color: "#e6a23c", percentage: 40 },
        { color: "#5cb87a", percentage: 60 },
        { color: "#1989fa", percentage: 80 },
        { color: "#6f7ad3", percentage: 100 },
      ],
    };
  },
  methods: {
    resetNameFilter() {
      this.$refs.filterTable.clearFilter("name");
    },
    clearFilter() {
      this.$refs.filterTable.clearFilter();
    },
    formatter(row, column) {
      return row.address;
    },
    filterTag(value, row) {
      return row.tag === value;
    },
    filterHandler(value, row, column) {
      const property = column["property"];
      return row[property] === value;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
      this.tableData.splice(index, 1);
    },
    deleteRows() {
      for (let i of this.multipleSelection) {
        for (let j in this.tableData) {
          if (i.code == this.tableData[j].code) {
            this.tableData.splice(j, 1);
          }
        }
      }
    },
    getFilters(key) {
      let arr = [];
      for (let i of this.tableData) {
        arr.push({
          text: i[key],
          value: i[key],
        });
      }
      return arr;
    },
    handleRowClick(row, column, event) {
      // console.log(row,column)
      this.$router.push({
        path: "/order/details",
        // name: 'mallList',
        // query: {
        //   code: row,
        // },
      });
    },
    getPerPageData() {
      let limit = this.$data.limit;
      let page = this.$data.currentPage;
      return this.tableData.slice(
        (page - 1) * limit,
        (page - 1) * limit + limit
      );
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.$data.limit = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.$data.currentPage = val;
    },
  },
};
</script>

<style scoped>
.block {
  text-align: center;
}
</style>